package com.todaynews.ui.me;

import android.graphics.drawable.Animatable2;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;

import com.todaynews.R;
import com.todaynews.frame.model.InfoResult;
import com.todaynews.frame.ui.fragment.BaseFragment;

public class UserFragment extends BaseFragment {

    private ImageView iv;
    AnimatedVectorDrawable animatedVectorDrawable;

    @Override
    public boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_me;
    }

    @Override
    public void init() {

        animatedVectorDrawable = (AnimatedVectorDrawable)
                ContextCompat.getDrawable(activity, R.drawable.refresh_vector);
        iv.setImageDrawable(animatedVectorDrawable);
        animatedVectorDrawable.start();
        //循环动画貌似只能这样。。。
        final Handler mainHandler = new Handler(Looper.getMainLooper());
        animatedVectorDrawable.registerAnimationCallback(new Animatable2.AnimationCallback() {
            @Override
            public void onAnimationEnd(Drawable drawable) {
                mainHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        animatedVectorDrawable.start();
                    }
                });
            }
        });
    }

    @Override
    public void loadData() {

    }

    @Override
    public void bind(View view) {
        super.bind(view);
        iv = view.findViewById(R.id.iv);
    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }
}
